package com.hzit.provider.controller;

import com.hzit.api.bean.Dept;
import com.hzit.provider.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dept")
public class DeptController {


    @Autowired
    private DeptService deptService;


    @GetMapping("/list")
    public List<Dept> list() {
        List<Dept> deptList = deptService.list();
        return deptList;
    }

    /**
     * @param dept
     * @return
     * @RequestBody:接受的参数 表示是一个json格式的数据
     */
    @PostMapping("/add")
    public boolean add(@RequestBody Dept dept) {
        return deptService.save(dept);
    }

    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public Dept get(@PathVariable("id") Long id) {
        Dept dept = deptService.getById(id);
        if (dept == null) {
            throw new RuntimeException("部门信息存在!");
        }
        //dept.setDb_source("db_8001");
        return dept;
    }
}
